package com.caibq.controller;


import com.caibq.service.ICallBackService;
import com.caibq.service.Impl.Work;
import org.testng.annotations.Test;

/**
 * projectName: demoBox
 *
 * @author: caicai
 * time: 2024/1/3 15:07 周三
 * description:异步回调
 */
public class CallBackTest {


    public static void main(String[] args) {
        System.out.println("准备发起异步调用");
        Thread thread = new Thread(() -> {
            Work work = new Work();
            try {
                work.doWork(new ICallBackService() {
                    @Override
                    public void callback(String... args) throws InterruptedException {
                        Thread.sleep(1000);
                        System.out.printf("正在执行回调动作:%s%n",args==null?"无参数":String.join(",", args));
                    }
                });
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        thread.start();

        System.out.println("继续干其他事儿");
    }
}
